package com.lxd.controller;

import java.util.List;

import com.lxd.entity.ClubRequest;
import com.lxd.entity.RegistrationVO;
import com.lxd.entity.TokenUserInfoDto;
import com.lxd.entity.query.RegistrationQuery;
import com.lxd.entity.po.Registration;
import com.lxd.entity.vo.ResponseVO;
import com.lxd.redis.RedisComponent;
import com.lxd.service.RegistrationService;
import com.lxd.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 *  Controller
 */
@RestController("registrationController")
@RequestMapping("/registration")
public class RegistrationController extends ABaseController{

	@Resource
	private RegistrationService registrationService;
	@Autowired
	private RedisComponent redis;
	/**
	 * 根据条件分页查询
	 */
	@RequestMapping("/loadDataList")
	public ResponseVO loadDataList(RegistrationQuery query,HttpServletRequest request){
		return getSuccessResponseVO(registrationService.findListByPage(query,request.getHeader("TOKEN")));
	}

	/**
	 * 新增
	 */
	@RequestMapping("/add")
	public ResponseVO add(Registration bean) {
		registrationService.add(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增
	 */
	@RequestMapping("/addBatch")
	public ResponseVO addBatch(@RequestBody List<Registration> listBean) {
		registrationService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 批量新增/修改
	 */
	@RequestMapping("/addOrUpdateBatch")
	public ResponseVO addOrUpdateBatch(@RequestBody List<Registration> listBean) {
		registrationService.addBatch(listBean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id查询对象
	 */
	@RequestMapping("/getRegistrationById")
	public ResponseVO getRegistrationById(Long id) {
		return getSuccessResponseVO(registrationService.getRegistrationById(id));
	}

	/**
	 * 根据Id修改对象
	 */
	@RequestMapping("/updateRegistrationById")
	public ResponseVO updateRegistrationById(@RequestBody Registration bean) {
		registrationService.updateRegistrationById(bean,bean.getId());
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据Id删除
	 */
	@RequestMapping("/deleteRegistrationById")
	public ResponseVO deleteRegistrationById(Long id) {
		registrationService.deleteRegistrationById(id);
		return getSuccessResponseVO(null);
	}

	@RequestMapping("/join")
	public ResponseVO join(@RequestBody RegistrationVO registration, HttpServletRequest request){
		String token = request.getHeader(Constants.HEADER_TOKEN);
		TokenUserInfoDto tokenUserInfoDto = redis.getTokenUserInfoDto(request.getHeader(Constants.HEADER_TOKEN));
		registrationService.join(registration,tokenUserInfoDto);
		return getSuccessResponseVO(null);
	}
}